" 优化器测试脚本
" 测试常量折叠、死代码消除等优化功能

echo "开始优化器测试"

" 常量折叠测试
echo "常量折叠测试:"
let a = 2 + 3 * 4
echo "2 + 3 * 4 =" a

let b = (10 - 5) / 2
echo "(10 - 5) / 2 =" b

let c = -5 + 3
echo "-5 + 3 =" c

" 复杂表达式
let d = 1 + 2 + 3 + 4
echo "1 + 2 + 3 + 4 =" d

" 死代码测试
echo "死代码消除测试:"
let unused_var_1 = 100
let unused_var_2 = 200
let used_var = 300

echo "使用的变量: " used_var

" 变量作用域测试
function! TestFunction()
    let local_unused = 42
    let result = used_var + 10
    return result
endfunction

let function_result = TestFunction()
echo "函数结果: " function_result

" 循环优化测试
echo "循环优化测试:"
let sum = 0
for i in [1, 2, 3, 4, 5]
    let sum = sum + i
endfor

echo "循环求和: " sum

" 条件语句优化测试
echo "条件语句测试:"
if (2 + 3) > (1 + 4)
    echo "条件为真"
else
    echo "条件为假"  " 这应该是死代码
endif

" 数学和字符串操作
echo "数学和字符串操作:"
let x = abs(-10)
let y = pow(2, 8)
let z = len("Hello World")

echo "abs(-10) = " x
echo "pow(2, 8) = " y
echo "len('Hello World') = " z

" 组合测试
echo "组合测试:"
let final_result = (x + y) * z
echo "最终结果: " final_result

echo "优化器测试完成"